<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //解构 可以从数组或对象中提取值并赋值给变量
        //数组解构
        let [x,y] = [1,2];
        console.log("x:",x,"y:",y);

        let[,,c] = [10,20,30];
        console.log("c:",c);
        //扩展运算符
        let [A, ...B] = [1,2,3,4,5];
        console.log("A:",A,"B:",B);
//A: 1 B:[2,3,4,5]
         let [x2,y2]=[100] //默认值
         console.log("x2:",x2,"y2:",y2);
// x2:100 y2:undefined;

        //两数交换;
        let x3 = 10;
        let y3 = 20; // 不加分号会报错;
        [x3,y3] = [y3,x3]
        console.log("x3:",x3,"y3:",y3)
        // x3:20 y3:10
      
        //对象解构;
        let person = {
            name:"梁轩",
            age:"20",
            gender:"男",
            web:"liangxuancode.com"
        }
        let {name} =person
        console.log("name:",name)
         let{name:username,gender}=person;//name重命名为username;
         console.log("username:",username,"gender:",gender)
    </script>
</body>
</html>